package com.huizhan.web.controller;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dm.model.v20151123.SingleSendMailRequest;
import com.aliyuncs.dm.model.v20151123.SingleSendMailResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

public class EmailUtil {

    public static void sendMail(String emails,String title,String content) {
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GBisX41cS9b6YzNJbLo", "rdlkFo4liNKabDxgXQJgaRAheGtSop");
        IAcsClient client = new DefaultAcsClient(profile);
        SingleSendMailRequest request = new SingleSendMailRequest();
        try {
            request.setAccountName("kefu@witexpo.cn");//控制台创建的发信地址
            request.setFromAlias("慧展科技");//发信人昵称
            request.setAddressType(1);
            request.setTagName("witexpo");//控制台创建的标签
            request.setReplyToAddress(true);
            //可以给多个收件人发送邮件，收件人之间用逗号分开，批量发信建议使用BatchSendMailRequest方式
            request.setToAddress(emails);//目标地址
            request.setSubject(title);//邮件主题
            request.setHtmlBody(content);//邮件正文
            SingleSendMailResponse httpResponse = client.getAcsResponse(request);

        } catch (ServerException e) {
            System.out.println("ErrCode : " + e.getErrCode());
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode : " + e.getErrCode());
            e.printStackTrace();
        }
    }
}